package xyz.renyumeng.xkm.shop.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static xyz.renyumeng.xkm.rabbitMQ.RabbitMqConstant.*;


/**
 * @author renyumeng
 * @date Created in 11:02 2023/7/4
 */

@Configuration
public class DirectRabbitConfig {


    @Bean
    public Queue esProductSaveQueue(){
        return new Queue(ES_PRODUCT_QUEUE,true);
    }

    @Bean
    public Queue esProductDeleteQueue(){
        return new Queue(ES_PRODUCT_DELETE_QUEUE,true);
    }

    @Bean
    DirectExchange esProductDirectExchange(){
        return new DirectExchange(ES_PRODUCT_EXCHANGE,true,false);
    }

    @Bean
    Binding bindingProductSaveDirect() {
        return BindingBuilder
                .bind(esProductSaveQueue())
                .to(esProductDirectExchange())
                .with(ES_PRODUCT_INSERT_KEY);
    }

    @Bean
    Binding bindingProductDeleteDirect(){
        return BindingBuilder
                .bind(esProductDeleteQueue())
                .to(esProductDirectExchange())
                .with(ES_PRODUCT_DELETE_KEY);
    }
}
